<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        "username" => "require|max:25",
        "password" => "require",
        "code" => "require|captcha",
        "user_name" => "require|max:25|unique:user",
        "phone_number" => "require|max:11|unique:user"
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        "username.require" => "用户名不能为空",
        "password.require" => "密码不能为空",
        "code.require" => "验证码不能为空",
        "code.captcha" => "验证码错误",

        // 编辑&&添加验证
        "user_name.require" => "用户名不能为空",
        "user_name.max" => "用户名不能超过25个字符",
        "user_name.unique" => "用户名已存在",
        "phone_number.require" => "手机号不能为空",
        "phone_number.max" => "手机号不能超过11个字符",
        "phone_number.unique" => "手机号已存在"
    ];

    protected $scene = [
        "login" => ["username", "password", "code"],
        "edit" => ["user_name","phone_number"]
    ];
}
